package se.opendataexchange.simulator;

import se.opendataexchange.common.AddressValue;

public class SimulatedDigitalValue extends AddressValue {

	public SimulatedDigitalValue(String name) {
		setName(name);
	}
	
	public SimulatedDigitalValue(String name, long interval) {
		setName(name);
		System.out.println("Creating ."+getName()+".");
		Simulator.addSimulatedValue(new SwitchGenerator(this, interval));
	}

	public class SwitchGenerator extends FunctionGenerator {

		private boolean prev;

		public SwitchGenerator(AddressValue val, long interval) {
			super(val, interval);
			prev = true;
		}

		@Override
		protected Object getValue() {
			prev = !prev;
			return prev;
		}
	}
}
